<?php require('includes/functions.php'); ?>
<!DOCTYPE html>
<html>
	<head>
		<title>Edit Employee</title>
		<script type="text/javascript" src="js/functions.js"></script>
		<link href="css/style.css" rel="stylesheet" type="text/css" />
	</head>
	<body>
		<?php 
			$id        = isset($_GET['id']) ? trim($_GET['id']):null;
			$employees = getEmployee($id); 
		?>
		<?php if ($employees): ?>
		<?php if (isset($_SESSION['error'])): ?>
			<?php echo "Error: ".$_SESSION['error'] ?>
			<?php unset($_SESSION['error']) ?>
		<?php endif ?>
		<?php if (isset($_SESSION['message'])): ?>
			<?php echo $_SESSION['message'] ?>
			<?php unset($_SESSION['message']) ?>
		<?php endif ?>
		<?php foreach ($employees as $employee): ?>
		<form name="myform" action="process/edit_employee.php" method="POST">
			<input type="hidden" name="id" value="<?php echo $employee->employee_id ?>" />
		<table cellspacing="0" cellpadding="5" border="1">
			<tr>
				<th>Employee ID</th>
				<td><?php echo $employee->employee_id ?></td>
			</tr>
			<tr>
				<th>Name</th>
				<td><input name="name" type="text" value="<?php echo $employee->name ?>" /></td>
			</tr>
			<tr>
				<th>Address</th>
				<td><textarea rows="5" name="address"><?php echo $employee->address ?></textarea></td>
			</tr>
			<tr>
				<th>Contact</th>
				<td><input name="contact" type="text" value="<?php echo $employee->contact ?>" /></td>
			</tr>
			<tr>
				<th>Email</th>
				<td><input name="email" type="text" value="<?php echo $employee->email ?>" /></td>
			</tr>
			<tr>
				<th>Gender</th>
				<td>
					<label><input type="radio" name="gender" value="male" <?php echo ($employee->gender == "male") ? 'checked="cheked"':null ?>/>Male</label>
					<label><input type="radio" name="gender" value="female" <?php echo ($employee->gender == "female") ? 'checked="cheked"':null ?>/>Female</label>
				</td>
			</tr>
			<tr>
				<th>Birthdate</th>
				<td><?php echo getDateFields($employee->birthdate) ?></td>
			</tr>
			<tr>
				<th>Department</th>
				<td><?php echo getDepartmentFields($employee->department_id) ?></td>
			</tr>	
			<tr>
				<th>Job</th>
				<td><?php echo getJobFields($employee->job_id) ?></td>
			</tr>
			<tr>
				<th>Status</th>
				<td><?php echo getJobStatusFields($employee->status_id) ?></td>
			</tr>
			<tr>
				<td colspan="2" align="right">
					<!--<input type="submit" value="Save" />-->
					<input type="button" value="Save" onclick="checkForSubmit()" />
				</td>
			</tr>
		</table>
		</form>
		<?php endforeach ?>
		<?php else: ?>
			No employees found.
		<?php endif ?>
		<center>
			<input type="button" value="Go back" onclick="location.href='index.php'" />
		</center>
	</body>
</html>